import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRPdfExporter;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;

import com.imprenta.ejb.EjbBuyProduct;
import com.imprenta.ejb.EjbEmpleado;
import com.imprenta.ejb.EjbPedido;
import com.imprenta.ejb.EjbRegistrarCliente;
import com.imprenta.entities.Cliente;
import com.imprenta.entities.Empleado;
import com.imprenta.entities.Login;
import com.imprenta.model.CatalogoBase;
import com.imprenta.model.PedidoBase;
import com.imprenta.model.ResumenPedidoBase;


public class TestClass {
	
	public static void main(String[] args) {
		Empleado e = new Empleado();
		Login l = new Login();
		l.setUsername("jason");l.setPassword("123");l.setRol("vendedor");
		e.setNombre("Jason");e.setApellido("perez");e.setTelefono("22222222");e.setCargo("Vendedor");e.setLogin(l);
		if (EjbEmpleado.SaveEmpleado(e, l)) {
			System.out.println("Insertado Correctamente");
		}else {
			System.err.println("Error");
		}
		
		
	}//fin main
	public static void createPdf(JasperPrint print) throws JRException{
		JRPdfExporter pdfExporter = new JRPdfExporter();
		pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
		pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE, new java.io.File("C:\\Compartida\\folder\\tmp\\reporte-pedido.pdf"));
		System.out.println("Exportando...");
		pdfExporter.exportReport();
		System.out.println("Done");
		
	}
	public static void updateCliente(){
		try {
			Cliente c = new Cliente();
			c.setClienteid(1);c.setNombre("alexander");c.setApellido("acevedo");c.setDireccion("altagracia");
			c.setTelefono("11111111");
			if (EjbRegistrarCliente.updateClienteById(c)) {
				System.out.println("Actualizado");
			}else{
				System.err.println("No actualizado");
			}
			

		} catch (Exception e) {
			// TODO: handle exception
			System.err.println(e.getMessage().toString());
		}
	}
	public static void getListaPedido(){
		try {
			ArrayList<PedidoBase> listaPedido = EjbPedido.getListaPedido();
			for (PedidoBase pedidoBase : listaPedido) {
				System.out.println(pedidoBase.getPedidoId());
				System.out.print(pedidoBase.getNombreCompleto());
				System.out.print(pedidoBase.getFecha());
				System.out.print(pedidoBase.getNombreProducto());
				System.out.print(pedidoBase.getCantidad());
				System.out.print(pedidoBase.getTotal());
				System.out.println();
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	public static void testSplit(){
		String a ="Cliente,Vendedor,Administrador";
		String [] aRol = a.split(",");
		String b="Administrador";
		for (int i = 0; i < aRol.length; i++) {
			if (b.equalsIgnoreCase(aRol[i])) {
				System.out.println(b + " es igual a " + aRol[i]);
			}else {
				System.err.println(b + " es diferente a " + aRol[i]);
			}
		}
	}
	
	public static void registrarPedido(){
		ResumenPedidoBase rpb = new ResumenPedidoBase("", "", "", "", "", 2, 8, 11, 13, 2, 10, 100);
		rpb.setIdcliente(1);
		if (EjbBuyProduct.insertTablaPedido(rpb)) {
			System.out.println("Success!!!!");
		}
		else {
			System.err.println("Failed");
		}
	}
	public static void testFecha(){
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		Date date = new Date();
		System.out.println(dateFormat.format(date));
		System.out.println();
		
		DateFormat dateFormat2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		System.out.println(dateFormat2.format(cal.getTime()));
	}
	
	@SuppressWarnings("rawtypes")
	public static void testSelect(){
		Collection<CatalogoBase> CatalogoCollection = new ArrayList<CatalogoBase>();
		CatalogoCollection.add(new CatalogoBase(1));
		CatalogoCollection.add(new CatalogoBase(2));
		CatalogoCollection.add(new CatalogoBase(3));
		CatalogoCollection.add(new CatalogoBase(1));
		
		Iterator i = selectById(CatalogoCollection, 1).iterator();
		while (i.hasNext()) {
			Object elemento = i.next();
			System.out.println(((CatalogoBase)elemento).getId());
		}
	}
	public static Collection<CatalogoBase> selectById(Collection<CatalogoBase> cBase, final int catalogoid){
		Predicate predicate = new Predicate() {
			
			@Override
			public boolean evaluate(Object arg0) {
				// TODO Auto-generated method stub
				CatalogoBase base = (CatalogoBase) arg0;
				return base.getId() == catalogoid ? true:false;
			}
		};
		
		Collection<CatalogoBase> catalogoResult = new ArrayList<CatalogoBase>();
		CollectionUtils.select(cBase, predicate,catalogoResult);
		return catalogoResult;
	}
}
